package com.wanmait.movies.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.wanmait.movies.util.DBHelper;
import com.wanmait.movies.vo.Movie;

public class ClickDao {
	private ClickDao() {}
	private static ClickDao clickDao = new ClickDao();
	public static ClickDao getObj() {
		return clickDao;
	}
	//���û��ĵ���ɾ��
	public void quxiaodianzan(int userId,int movieId) {
		Connection co = DBHelper.getDBHelper().getconn();
		String sql="DELETE FROM  click where user_id=? and movie_id=?";
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps=co.prepareStatement(sql);
			ps.setInt(1, userId);
			ps.setInt(2, movieId);
			ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			DBHelper.getDBHelper().close(rs, ps, co);
		}
	}
	public void quxiaodianzan(int movieId) {
		Connection co = DBHelper.getDBHelper().getconn();
		String sql="DELETE FROM  click where  movie_id=?";
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps=co.prepareStatement(sql);
			ps.setInt(1, movieId);
			ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			DBHelper.getDBHelper().close(rs, ps, co);
		}
	}
	
	
	//���û��ĵ�����ӵ����ݿ�
	public void dainzan(int userId,int movieId) {
		Connection co = DBHelper.getDBHelper().getconn();
		String sql="insert into click(user_id,movie_id) values(?,?)";
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps=co.prepareStatement(sql);
			ps.setInt(1, userId);
			ps.setInt(2, movieId);
			ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			DBHelper.getDBHelper().close(rs, ps, co);
		}
	}
}
